fix: allow first-time HODLMM deposit bins#583
Open
macbotmini-eng wants to merge 1 commit into
Open
Conversation
✅ Validation PassedSkill: All checks passed. This submission is ready for review. |
biwasxyz
added a commit
to aibtcdev/skills
that referenced
this pull request
May 26, 2026
… user-bins 404 (#397) * fix(bitflow-hodlmm-deposit): allow first-time deposit by handling BFF user-bins 404 `getUserBins` calls `fetchJson` with no error handling. BFF returns HTTP 404 with detail "Pool {pool} not found or user {addr} has no pool bins" when a wallet has zero existing LP positions in the pool. That is the normal first-time deposit case (explicitly supported per SKILL.md), not an error, but the throw bubbles up and crashes `doctor`, `status`, and `run` before any deposit logic executes. Wrap the fetch in try/catch. Catch ONLY the specific `HTTP 404 from ... has no pool bins` response shape and return an empty bins array. Let any other 404 or API failure propagate unchanged. Downstream code at line 498+ already handles an empty `bins` array correctly via `.filter(b => b.userLiquidity > 0n)` — empty array is the right shape for postcondition-plan adjustment to treat the wallet as a new LP. Companion fix to staging PR BitflowFinance/bff-skills#583 which patches the same bug in the staging copy of this skill. Verified end-to-end on Stacks mainnet against three wallet shapes: - Fresh wallet `SP3YWTZQQ7ZYHG1ECEG6AJAT4KX36W2NA7Q6TCKBG` (was failing): doctor and status both now succeed; status preview generates full deposit plan (activeBin 648, 3-bin equal-split, slippage-protected minDlp, bounded postcondition). - Wallet with existing positions `SP2G6TM8JCRNK6WSPQE8S86FP2W3A4FEVGZCCCQT8`: doctor still works (no regression). - Wallet with positions in OTHER pools but not this one (`SP2G6TM8...` + `--pool-id dlmm_9`): correctly handled as first-time. Verified across dlmm_1, dlmm_3, dlmm_7 pools. `bun run typecheck` passes. * docs(bitflow-hodlmm-deposit): note fetchJson error-format coupling in 404 catch Add a comment flagging that the empty-state catch is coupled to fetchJson's internal error message format ("HTTP 404 from ..."). If fetchJson's format ever changes, the catch silently fails — the 404 propagates instead of returning [], which is safe (no data loss) but the fix stops working with no diagnostic signal. The note tells a future fetchJson refactor where to look. Comment-only change; behavior identical to the previous commit. * fix(bitflow-hodlmm-deposit): clarify active-bin coordinate systems in status preview The status preview printed `observedActiveBinId` (BFF absolute, e.g. 646) next to `routerExpectedBinId` (on-chain relative, e.g. 146) with no labels, making the 500-bin center offset read as router-vs-BFF drift that would revert at maxDeviation 0. Verified against the live router (dlmm-liquidity-router-v-1-1 add-relative-liquidity-same-multi) and pool (dlmm-pool-sbtc-usdcx-v-1-bps-10): the contract's ERR_ACTIVE_BIN_TOLERANCE assert compares its own on-chain get-active-bin-id (returned 146) against the passed expected-bin-id (646-500=146), so a synced pool yields delta 0 and passes even at maxDeviation 0. The offset is by design (MIN_BIN_ID -500 / MAX_BIN_ID 500), not drift. Rename fields to bffActiveBinId / onChainExpectedBinId and document the coordinate systems so the broadcast path is not misdiagnosed as blocked. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: macbotmini-eng <macbotmini-eng@users.noreply.github.com> Co-authored-by: biwasbhandari <biwas2059@gmail.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the first-time HODLMM deposit path for
bitflow-hodlmm-deposit.The skill documentation says first-time deposits into valid protocol bins are supported, but the live Bitflow user-bin endpoint currently returns HTTP 404 when the wallet has no existing pool bins. That observed response should mean "no existing wallet position yet," not "the pool is unusable," after the separate pool and bin metadata checks pass.
API surface check
Live spec checked: https://bff.bitflowapis.finance/api/app/openapi.json
BFF API1.0.0, OpenAPI3.1.0./api/app/v1/pools/{pool_id}is documented asGet Pool By Id: pool metadata by pool id./api/app/v1/poolsis documented as pool listing/filtering metadata./api/app/v1/users/{user_address}/positions/{pool_id}/binsis documented asGet User Pool Bins: bin information for a specific user and pool, withfresh=truesupport and user-position cache/fallback headers.200and422responses; it does not document404as a pool-existence signal.That split is the behavior this PR codifies: pool validity comes from pool/bin metadata checks, while the user-bin endpoint is wallet-specific position state. A missing user-position row for a wallet with no existing bins is not enough to reject a first-time deposit when the pool metadata and protocol-bin data are valid.
Quote-side cross-check: https://bff.bitflowapis.finance/api/quotes/openapi.json documents
/api/quotes/v1/bins/{pool_id}as pool bin reserves, prices, and liquidity information, which is the protocol-bin side of the same separation.Change
HTTP 404 ... has no pool binsuser-position response as an empty wallet-bin set.Validation
Pre-proof route validation, before the #559 route consumed the funded sBTC:
bun run skills/bitflow-hodlmm-deposit/bitflow-hodlmm-deposit.ts status --wallet SP2G6TM8JCRNK6WSPQE8S86FP2W3A4FEVGZCCCQT8 --pool-id dlmm_1 --amount-x 4300 --amount-y 0success700hasExistingPosition: falsedenywallet sends <= 4300 sBTCCurrent live reruns with the same
4300amount now correctly block on insufficient sBTC because that balance was used by the #559 proof route. The important behavior from this PR remains verified: the specific first-timehas no pool binsAPI response no longer stops planning before pool/bin metadata, token balance, and postcondition checks run.Additional checks:
bitflow-hodlmm-depositwith 0 errors and 0 warnings.bun run scripts/validate-frontmatter.tsbitflow-hodlmm-depositpassed with 0 errors and 0 warningsdca,stacking-delegation, andzest-yield-managergit diff --checkWhy this matters
This is required for composed routes like #559 where the first route proof starts from idle sBTC and creates the wallet's first HODLMM position in an existing pool/bin.